package com.donger.auth.validate;


import com.donger.auth.exception.InvalidException;
import com.donger.auth.handler.ValidateCodeType;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Map;


/**
 * 验证码处理器
 */

@AllArgsConstructor
@Component
public class BuildValidateCodeProcessor {


    private final Map<String, ValidateCodeProcessor> validateCodeProcessors;


    public ValidateCodeProcessor build(ValidateCodeType type) {

        String name = type.getParamNameOnValidate();
        ValidateCodeProcessor processor = validateCodeProcessors.get(name);
        if (processor == null) {
            throw new InvalidException("验证码处理器" + name + "不存在");
        }
        return processor;
    }

}
